#ifndef __MSGCLASS_H__
#define __MSGCLASS_H__

#include "env.h"
#include "msgmacro.h"
#include "output.h"

class MsgBaseClass
{
public:
	MsgBaseClass() {msgtype = 0;}
	~MsgBaseClass() {}
	int msgtype;
	inline virtual byteArrays encodeMsgClass() {byteArrays ba;return ba;}
	inline virtual void decodeByteArrays(byteArrays ba) {}
};


class MsgLoginAttempt : public MsgBaseClass {
public:
	MsgLoginAttempt() {msgtype = WMSG_LOGINATTEMPT;}
	std::string name;
	std::string key;

	ENCODE_CLASS_S
		ENCODE_STRING(name)
		ENCODE_STRING(key)
	ENCODE_CLASS_E

	DECODE_CLASS_S
		DECODE_STRING(name)
		DECODE_STRING(key)
	DECODE_CLASS_E
};

class MsgLoginFail : public MsgBaseClass {
public:
	MsgLoginFail() {msgtype = WMSG_LOGINFAIL;}
	std::string name;
	std::string key;

	ENCODE_CLASS_S
		ENCODE_STRING(name)
		ENCODE_STRING(key)
	ENCODE_CLASS_E

	DECODE_CLASS_S
		DECODE_STRING(name)
		DECODE_STRING(key)
	DECODE_CLASS_E
};

class MsgLoginSuccessPlayerData : public MsgBaseClass {
public:
	std::string playerName;
	short playerLevel;
	int playerExp;
	char playerSex;

	ENCODE_CLASS_S
		ENCODE_STRING(playerName)
		ENCODE_SHORT(playerLevel)
		ENCODE_INT(playerExp)
		ENCODE_BYTE(playerSex)
	ENCODE_CLASS_E

	DECODE_CLASS_S
		DECODE_STRING(playerName)
		DECODE_SHORT(playerLevel)
		DECODE_INT(playerExp)
		DECODE_BYTE(playerSex)
	DECODE_CLASS_E
};

class MsgLoginSuccessPlayerItem : public MsgBaseClass {
public:
	short itemPos;
	int itemID;
	std::string args;

	ENCODE_CLASS_S
		ENCODE_SHORT(itemPos)
		ENCODE_INT(itemID)
		ENCODE_STRING(args);
	ENCODE_CLASS_E

	DECODE_CLASS_S
		DECODE_SHORT(itemPos)
		DECODE_INT(itemID)
		DECODE_STRING(args);
	DECODE_CLASS_E
};

class MsgLoginSuccessPlayerTask : public MsgBaseClass {
public:
	int taskID;
	char status;
	int atime;
	int stime;

	ENCODE_CLASS_S
		ENCODE_INT(taskID)
		ENCODE_BYTE(status)
		ENCODE_INT(atime)
		ENCODE_INT(stime)
	ENCODE_CLASS_E

	DECODE_CLASS_S
		DECODE_INT(taskID)
		DECODE_BYTE(status)
		DECODE_INT(atime)
		DECODE_INT(stime)
	DECODE_CLASS_E
};

class MsgLoginSuccessPlayerCounter : public MsgBaseClass {
public:
	int cid;
	std::string args;
	int c1;
	int c2;
	int c3;
	int ctime;
	int utime;

	ENCODE_CLASS_S
		ENCODE_INT(cid)
		ENCODE_STRING(args)
		ENCODE_INT(c1)
		ENCODE_INT(c2)
		ENCODE_INT(c3)
		ENCODE_INT(ctime)
		ENCODE_INT(utime)
	ENCODE_CLASS_E

	DECODE_CLASS_S
		DECODE_INT(cid)
		DECODE_STRING(args)
		DECODE_INT(c1)
		DECODE_INT(c2)
		DECODE_INT(c3)
		DECODE_INT(ctime)
		DECODE_INT(utime)
	DECODE_CLASS_E
};

class MsgLoginSuccess : public MsgBaseClass {
public:
	MsgLoginSuccess() {msgtype = WMSG_LOGINSUCCESS;}
	int playerid;
	MsgLoginSuccessPlayerData playerdata;
	_wserVector<MsgLoginSuccessPlayerItem> itemdata;
	_wserVector<MsgLoginSuccessPlayerTask> taskdata;
	_wserVector<MsgLoginSuccessPlayerCounter> counterdata;

	ENCODE_CLASS_S
		ENCODE_INT(playerid)
		ENCODE_MSGCLASS(playerdata)
		ENCODE_MSGVECTOR(itemdata)
		ENCODE_MSGVECTOR(taskdata)
		ENCODE_MSGVECTOR(counterdata)
	ENCODE_CLASS_E

	DECODE_CLASS_S
		DECODE_INT(playerid)
		DECODE_MSGCLASS(playerdata)
		DECODE_MSGVECTOR(itemdata)
		DECODE_MSGVECTOR(taskdata)
		DECODE_MSGVECTOR(counterdata)
	DECODE_CLASS_E
};

class MsgAcceptConnect : public MsgBaseClass
{
public:
	MsgAcceptConnect() {msgtype = WMSG_ACCEPTCONNECT;}

	ENCODE_CLASS_S
	ENCODE_CLASS_E

	DECODE_CLASS_S
	DECODE_CLASS_E
};

class MsgCloseConnect : public MsgBaseClass
{
public:
	MsgCloseConnect() {msgtype = WMSG_CLOSEDCONNECT;}

	ENCODE_CLASS_S
	ENCODE_CLASS_E

	DECODE_CLASS_S
	DECODE_CLASS_E
};

class MsgTimeout : public MsgBaseClass
{
public:
	MsgTimeout() {msgtype = WMSG_TIMEOUT;}
	int timeoutid;
	byteArrays param;

	ENCODE_CLASS_S
		ENCODE_INT(timeoutid)
		ENCODE_BYTEARRAYS(param)
	ENCODE_CLASS_E

	DECODE_CLASS_S
		DECODE_INT(timeoutid)
		DECODE_BYTEARRAYS(param)
	DECODE_CLASS_E
};

#endif //__MSGCLASS_H__
